var db = require('../core/database.js');


function triggerActions(sensor_id, data) {
  db.getSensorActions(sensor_id, function(actions) {
  	for(var i = 0; i < actions.length; i++)
  	{
      console.log(sensor_id + ' -- ' + actions[i]);
    
      require('../modules/'+actions[i].action+'.js').execute(data, actions[i].idModule);
    }
  });
}

function launchAllModules() {
	db.getAllModules(function (modules) {
		
		if (modules != null) {
		
			for (var i=0; i<modules.length; i++) {
				var module = modules[i];
				require('../modules/'+module['module']+'/module.js').init(module['rowid']);
			}
		}
		
	});
}

module.exports.process_sensor = triggerActions;
module.exports.launchAllModules = launchAllModules;
